package com.pureut.system.controller;

import java.util.Arrays;
import java.util.List;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.system.domain.InformationEntry;
import com.pureut.system.domain.vo.InformationEntryVo;
import com.pureut.system.service.IInformationEntryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * @Author: pureut
 * @Date: 2025-04-08 16:25:49
 * @Desc: 信息录入表Controller
 */
@RestController
@RequestMapping("/system/informationEntry")
public class InformationEntryController  extends BaseController {

    /**
     * 信息录入表Service
     */
    @Resource
    private IInformationEntryService informationEntryService;

    /**
     * 查询信息录入表列表
     * @param: params 参数列表
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("informationEntry-list")
    @GetMapping("/list")
    public TableDataInfo list( InformationEntryVo informationEntryVo) {
        startPage();
        LambdaQueryWrapper<InformationEntry> resultQuery = new LambdaQueryWrapper<InformationEntry>();
        if(ObjectUtil.isNotNull(informationEntryVo.getExperienceSource())){
            resultQuery.like(InformationEntry::getExperienceSource, informationEntryVo.getExperienceSource());
        }
        if(ObjectUtil.isNotNull(informationEntryVo.getProductModel())){
            resultQuery.like(InformationEntry::getProductModel, informationEntryVo.getProductModel());
        }

        if(ObjectUtil.isNotNull(informationEntryVo.getStartTime())&&ObjectUtil.isNotNull(informationEntryVo.getEndTime())){
            resultQuery.between(InformationEntry::getCreateTime, informationEntryVo.getStartTime(),informationEntryVo.getEndTime());
        }
        if(ObjectUtil.isNotNull(informationEntryVo.getFailureCategory())){
            resultQuery.like(InformationEntry::getFailureCategory, informationEntryVo.getFailureCategory());
        }
        return getDataTable(informationEntryService.list(resultQuery));
    }


    /**
     * 获取信息录入表详细信息
     * @param: id 信息录入表主键
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("informationEntry-query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(informationEntryService.getById(id));
    }

    /**
     * 新增信息录入表
     * @param: informationEntry 信息录入表对象
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("informationEntry-add")
    @PostMapping
    public AjaxResult add(@RequestBody InformationEntryVo informationEntryVo) {
        return toAjax(informationEntryService.save(informationEntryVo));
    }

    /**
     * 修改信息录入表
     * @param: informationEntry 信息录入表对象
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("informationEntry-edit")
    @PutMapping
    public AjaxResult edit( @RequestBody InformationEntryVo informationEntryVo) {
        return toAjax(informationEntryService.updateById(informationEntryVo));
    }

    /**
     * 删除信息录入表
     * @param: id 信息录入表主键
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("informationEntry-remove")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(informationEntryService.removeByIds(Arrays.asList(ids)));
    }
}
